-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Request response storage typing #11766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Request response storage typing #11766
Conversation
CodSpeed Performance ReportMerging #11766 will not alter performanceComparing Summary
|
|
I believe this one's ready for review, or, at the very least, tests are passed locally. Also, I didn't add warnings for string keys usage, since it'd be too spammy to raise them on a per-request basis. |
|
|
||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring is enough.
| pass |
| def __setitem__(self, key: str, value: Any) -> None: ... | ||
|
|
||
| def __setitem__(self, key: str | RequestKey[_T], value: Any) -> None: | ||
| self._state[key] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably put the same warning in:
| self._state[key] = value | |
| if not isinstance(key, RequestKey): | |
| warnings.warn( | |
| "It is recommended to use web.RequestKey instances for keys.\n" | |
| + "https://docs.aiohttp.org/en/stable/web_advanced.html" | |
| + "#application-s-config", | |
| category=NotAppKeyWarning, | |
| stacklevel=2, | |
| ) | |
| self._state[key] = value |
We can probably just leave the warning as NotAppKeyWarning for backwards compatibility..
| This class should be used for the keys in :class:`Request` and | ||
| :class:`BaseRequest`. They provide a type-safe alternative to | ||
| `str` keys when checking your code with a type checker (e.g. mypy). | ||
| They also avoid name clashes with keys from different libraries etc. | ||
|
|
||
| :param name: A name to help with debugging. This should be the same as | ||
| the variable name (much like how :class:`typing.TypeVar` | ||
| is used). | ||
|
|
||
| :param t: The type that should be used for the value in the dict (e.g. | ||
| `str`, `Iterator[int]` etc.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep maintenance simpler, we should probably do something like:
| This class should be used for the keys in :class:`Request` and | |
| :class:`BaseRequest`. They provide a type-safe alternative to | |
| `str` keys when checking your code with a type checker (e.g. mypy). | |
| They also avoid name clashes with keys from different libraries etc. | |
| :param name: A name to help with debugging. This should be the same as | |
| the variable name (much like how :class:`typing.TypeVar` | |
| is used). | |
| :param t: The type that should be used for the value in the dict (e.g. | |
| `str`, `Iterator[int]` etc.) | |
| Keys for use in :class:`Request`. | |
| See :class:`AppKey` for more details. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11766 +/- ##
=======================================
Coverage 98.74% 98.74%
=======================================
Files 127 127
Lines 43754 43826 +72
Branches 2328 2332 +4
=======================================
+ Hits 43204 43276 +72
Misses 389 389
Partials 161 161
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
What do these changes do?
RequestKey&ResponseKeyclasses, which enable static typing checks in corresponding classes with dict-like storages, similarly toAppKey;Are there changes in behavior for the user?
Users may now use
RequestKey&ResponseKeyin request & response objects, in addition to string keys.Is it a substantial burden for the maintainers to support this?
Related issue number
This issue should close #11762.
Checklist
CONTRIBUTORS.txtCHANGES/foldername it
<issue_or_pr_num>.<type>.rst(e.g.588.bugfix.rst)if you don't have an issue number, change it to the pull request
number after creating the PR
.bugfix: A bug fix for something the maintainers deemed animproper undesired behavior that got corrected to match
pre-agreed expectations.
.feature: A new behavior, public APIs. That sort of stuff..deprecation: A declaration of future API removals and breakingchanges in behavior.
.breaking: When something public is removed in a breaking way.Could be deprecated in an earlier release.
.doc: Notable updates to the documentation structure or buildprocess.
.packaging: Notes for downstreams about unobvious side effectsand tooling. Changes in the test invocation considerations and
runtime assumptions.
.contrib: Stuff that affects the contributor experience. e.g.Running tests, building the docs, setting up the development
environment.
.misc: Changes that are hard to assign to any of the abovecategories.
Make sure to use full sentences with correct case and punctuation,
for example:
Use the past tense or the present tense a non-imperative mood,
referring to what's changed compared to the last released version
of this project.